package com.curtain.koreyoshi.view.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.text.method.ScrollingMovementMethod;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curtain.koreyoshi.utils.ResUtil;


/**
 * Created by leejunpeng on 2016/4/5.
 */
public class AdChargeContentView extends LinearLayout {

    private static final int AD_ICON_ID = 1001;

    public CircleImageView iv_ad_icon;
    public TextView tv_ad_title;
    public TextView tv_ad_desc;
    public RoundButton btn_install;
    public RoundButton btn_cancel;
    public AdChargeContentView(Context context) {
        super(context);
        setOrientation(LinearLayout.HORIZONTAL);
        GradientDrawable background = new GradientDrawable();
        background.setColor(Color.parseColor("#ffffff"));
        background.setCornerRadius(ResUtil.dip2px(context, 8));
        setBackgroundDrawable(background);
        LinearLayout iconLayout = new LinearLayout(context);
        iconLayout.setGravity(Gravity.CENTER);
        LayoutParams iconLayParams = new LayoutParams(0, LayoutParams.MATCH_PARENT,2);
        //广告的ICON
        iv_ad_icon = new CircleImageView(context);
        iv_ad_icon.setType(CircleImageView.TYPE_ROUND);
        iv_ad_icon.setCornerRadius(30);
        iv_ad_icon.setId(AD_ICON_ID);
        LayoutParams iconParams = new LayoutParams(ResUtil.heightDip2px(130), ResUtil.heightDip2px(130));
        iconLayout.addView(iv_ad_icon,iconParams);
        this.addView(iconLayout, iconLayParams);

        LinearLayout content = new LinearLayout(context);
        content.setOrientation(LinearLayout.VERTICAL);
        content.setGravity(Gravity.CENTER_HORIZONTAL);
        LayoutParams contentParams = new LayoutParams(0, LayoutParams.MATCH_PARENT,3);
        contentParams.topMargin = ResUtil.heightDip2px(30);
        contentParams.bottomMargin = ResUtil.heightDip2px(30);

        //广告标题
        tv_ad_title = new TextView(context);
        tv_ad_title.setTextColor(Color.parseColor("#2fa5f1"));
        tv_ad_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResUtil.heightDip2px(30));
        tv_ad_title.setSingleLine(true);
        tv_ad_title.setGravity(Gravity.CENTER_HORIZONTAL);
        tv_ad_title.setTypeface(Typeface.DEFAULT_BOLD);
        LayoutParams titleParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        content.addView(tv_ad_title,titleParams);

        //描述
        tv_ad_desc = new TextView(context);
        tv_ad_desc.setTextColor(Color.parseColor("#2ca1ed"));
        tv_ad_desc.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResUtil.heightDip2px(20));
        tv_ad_desc.setLines(5);
        tv_ad_desc.setMovementMethod(new ScrollingMovementMethod());
        LayoutParams descParams = new LayoutParams(LayoutParams.MATCH_PARENT, 0,1);
        descParams.topMargin = ResUtil.heightDip2px(20);
        content.addView(tv_ad_desc,descParams);

        //按钮
        btn_install = new RoundButton(context);
        btn_install.setText("Click Download");
        btn_install.setPadding(ResUtil.widthDip2px(20),ResUtil.heightDip2px(10),ResUtil.widthDip2px(20),ResUtil.heightDip2px(10));
        btn_install.setNormorColor(Color.parseColor("#279be6"));
        btn_install.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResUtil.heightDip2px(22));
        btn_install.setTextColor(Color.parseColor("#ffffff"));
        LayoutParams btnParams = new LayoutParams(LayoutParams.WRAP_CONTENT, ResUtil.heightDip2px(60));
        btnParams.gravity = Gravity.CENTER;
        content.addView(btn_install,btnParams);
        this.addView(content,contentParams);

        btn_cancel = new CancelRoundButton(context);
        btn_cancel.setCornerRadius(50);
        btn_cancel.setNormorColor(0xffc7c7c7);
        LayoutParams closeParams = new LayoutParams(ResUtil.heightDip2px(40), ResUtil.heightDip2px(40));
        closeParams.rightMargin = ResUtil.heightDip2px(13);
        closeParams.topMargin = ResUtil.heightDip2px(13);
        this.addView(btn_cancel, closeParams);
    }
}
